<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../lib/axios.js"></script>
</head>
<body>
    <h1>登录</h1>
    用户名: <input type="text" class="user"><br>
    密  码: <input type="text" class="pwd"><br>
    <button class="btn">登录</button>
    <script>
        let user=document.querySelector('.user');
        let pwd=document.querySelector('.pwd');
        let btn=document.querySelector('.btn');
        // 给登录添加点击事件
        btn.onclick = function(e) {
            // 阻止默认行为
            e.preventDefault()
            axios.post('/login',{user:user.value,pwd:pwd.value}).then((res) => {
                console.log(res.data);
                if(res.data==='登录成功'){
                    location.href='./index2.html'
                }
            })
            
        }
    </script>
</body> 
</html>